<?php

namespace App\Models\Factory;

use App\Helpers\RestResponseFactory;
use App\Helpers\RestUtils;
use App\Models\AbsModelFactory;
use App\Models\Orm\Popup;
use App\Models\Orm\PopupUser;


/**
 * 任务弹窗工厂
 * Class SmsFactory
 * @package App\Models\Factory
 */
class PopupFactory extends AbsModelFactory
{
        //拿到弹窗
        public static  function getPopup($type,$position)
        {
            $result = Popup::where('type', $type)->where('position', $position)->where('status', 1)->first();
            return $result ? $result :'';
        }


        //拿到每个用户弹窗
         public static  function getUserPopup($type,$position,$userId)
        {

        $result = PopupUser::where('type',$type)->where('position',$position)->where('user_id',$userId)->first();
        //有的话说明不需要提醒了
        if($result){
            $data["status"] ="0";
          return $data;
        }else{
            $data = self::getPopup($type,$position);
            $data['status'] = "1";
           return $data;
        }
    }

    /**
     *点击我知道了,插入个性弹窗表一条数据
     * @param $type
     * @param $position
     * @param $userId
     * @return mixed
     */
    public static  function createPopup($type,$position,$userId)
    {

        $popup['type'] = $data['type'] = $type;
        $popup['position'] = $data['position'] = $position;
        $popup['user_id'] = $data['user_id'] = $userId;
        $data['create_time'] = date('Y-m-d H:i:s', time());
        $data['update_time'] = date('Y-m-d H:i:s', time());
        $result = PopupUser::firstOrCreate($popup,$data);
       return $result;
    }

}

